import 'package:flutter/material.dart';
import 'package:god_logistics/pages/index.dart';
import 'package:god_logistics/pages/loginVIew/loginPage.dart';
import 'package:god_logistics/pages/loginVIew/refresh.dart';
import 'package:god_logistics/pages/mine/settingPage.dart';
import 'package:god_logistics/pages/tabbar.dart';
import 'package:god_logistics/utils/tokenManage.dart';

void main() {
  runApp(
    MaterialApp(
      // home: tabpage(),
      // home: Loginpage(),
      routes: {
        '/': (context) => const allPage(),
        '/tabbar': (context) => const tabpage(),
        '/login': (context) => const Loginpage(),
        '/settingpage': (context) => const Settingpage(),
        // '/RefreshLoadMorePage': (context) => RefreshLoadMorePage(),
      },
      initialRoute: '/',
      onGenerateRoute: (settings) {
        final tokenManager = TokenManager();
        final token = tokenManager.getToken() ?? '';
        if (token.isEmpty && settings.name != '/login') {
          return MaterialPageRoute(builder: (context) => const Loginpage());
        }
      },
    ),
  );
}
